package entities

import (
	"gitee.com/igolang/imoney/internal/app/system/entities/constants"
	"gitee.com/igolang/pkg/xgin/xvalidator"
	"github.com/pkg/errors"
)

type UserOnlinePageListReq struct {
	PageListReq
	UserName string `json:"userName" form:"userName"`
}

type UserPageListReq struct {
	PageListReq
	UserName    string `json:"userName" form:"userName"`
	PhoneNumber string `json:"phonenumber" form:"phonenumber"`
	DeptId      int64  `json:"deptId" form:"deptId"`
}

type UserProfileReq struct {
	Email       string `json:"email" form:"email" binding:"required,email" validator_msg:"请输入正确的邮箱地址"`
	NickName    string `json:"nickName" form:"nickName" binding:"required" validator_msg:"用户昵称不能为空"`
	PhoneNumber string `json:"phonenumber" form:"phonenumber" binding:"required,mobile" validator_msg:"请输入正确的手机号"`
	Sex         string `json:"sex" form:"sex"`
}

func (e *UserProfileReq) FormatErr(err error) error {
	return xvalidator.FormatError(e, err)
}

type UserAddReq struct {
	DeptId      int64   `json:"deptId" form:"deptId"`
	Email       string  `json:"email" form:"email" binding:"omitempty,email"`
	NickName    string  `json:"nickName" form:"nickName" binding:"required"`
	Password    string  `json:"password" form:"password" binding:"required,password"`
	PhoneNumber string  `json:"phonenumber" form:"phonenumber" binding:"omitempty,mobile"`
	PostIds     []int64 `json:"postIds" form:"postIds"`
	Remark      string  `json:"remark" form:"remark"`
	RoleIds     []int64 `json:"roleIds" form:"roleIds"`
	Sex         string  `json:"sex" form:"sex"`
	Status      string  `json:"status" form:"status"`
	UserName    string  `json:"userName" form:"userName" binding:"required,alphanum"`
}

func (e *UserAddReq) GetMessages() map[string]map[string]error {
	return map[string]map[string]error{
		"email": {
			"email": errors.New("请输入正确的邮箱地址"),
		},
		"nickName": {
			"required": errors.New("用户昵称不能为空"),
		},

		"userName": {
			"required": errors.New("用户名称不能为空"),
		},
		"phonenumber": {
			"mobile": errors.New("请输入正确的手机号"),
		},

		"password": {
			"required": errors.New("密码不能为空"),
			"password": constants.PasswordErr,
		},
	}
}

func (e *UserAddReq) FormatErr(err error) error {
	return xvalidator.FormatValidatorError(e, err, "json")
}

type UserSaveReq struct {
	UserId      int64   `json:"userId" form:"userId" binding:"required" validator_msg:"请指定用户"`
	DeptId      int64   `json:"deptId" form:"deptId"`
	Email       string  `json:"email" form:"email" binding:"omitempty,email" validator_msg:"请输入正确的邮箱地址"`
	NickName    string  `json:"nickName" form:"nickName" binding:"required" validator_msg:"用户昵称不能为空"`
	PhoneNumber string  `json:"phonenumber" form:"phonenumber" binding:"omitempty,mobile" validator_msg:"请输入正确的手机号"`
	PostIds     []int64 `json:"postIds" form:"postIds"`
	Remark      string  `json:"remark" form:"remark"`
	RoleIds     []int64 `json:"roleIds" form:"roleIds"`
	Sex         string  `json:"sex" form:"sex"`
	Status      string  `json:"status" form:"status"`
}

func (u *UserSaveReq) FormatErr(err error) error {
	return xvalidator.FormatError(u, err)
}
